package com.neuedu.corejava.ch14;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class ChatRoomServer {
	private Map<String, Socket> clienMap = new HashMap<String, Socket>();

	public void start(int port) {
		ServerSocket serverSocket = null;
		try {
			serverSocket = new ServerSocket(port);
			while (true) {
				Socket socket = serverSocket.accept();
				String ip = socket.getInetAddress().getHostAddress();
				clienMap.put(ip, socket);
				
				new Thread(new ChatRoom(socket, clienMap)).start();
				
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
